package com.ruoyi.web.controller.jjm;

import com.ruoyi.framework.web.service.DictService;
import com.ruoyi.jjm.domain.Baolianren;
import com.ruoyi.jjm.domain.ClientUser;
import com.ruoyi.jjm.domain.ClientUserOrder;
import com.ruoyi.jjm.domain.GridMemeber;
import com.ruoyi.jjm.service.*;
import com.ruoyi.system.domain.SysDept;
import com.ruoyi.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/mobile")
public class MobileController {

    @Autowired
    private ISysDeptService deptService;

    @Autowired
    private IClientUserService clientUserService;

    @Autowired
    private IGridMemeberService gridMemeberService;

    @Autowired
    private IBaolianrenService baolianrenService;

    @Autowired
    private IClientUserOrderService clientUserOrderService;

    @Autowired
    private IVillageService villageService;
    @Autowired
    private DictService dictService;
    @RequestMapping("/client/{id}")
    public String user(@PathVariable("id") Long id, ModelMap modelMap){
        modelMap(id,modelMap);

        return "jjm/clientUser/mobileUser";
    }
    @RequestMapping("/clientUser/{id}")
    public String clientUser(@PathVariable("id") Long id, ModelMap modelMap){
        modelMap(id,modelMap);

        return "jjm/clientUser/mobileUser1";
    }

    private void modelMap(Long id, ModelMap modelMap){
        ClientUser user = clientUserService.selectClientUserById(id);
        if(user.getArea() != null){
            user.setAreaValue(dictService.getLabel("keep_warn_area",user.getArea().toString()));
        }
        if(user.getKeepwarmType() != null){
            user.setKeepwarmTypeValue(dictService.getLabel("keep_warm_type",user.getKeepwarmType().toString()));
        }
        if(user.getGridId() != null){
            GridMemeber gridMemeber = gridMemeberService.selectGridMemeberById(user.getGridId());
            user.setGridMemeber(gridMemeber);
        }
        if(user.getBaolianrenId() != null){
            Baolianren baolianren = baolianrenService.selectBaolianrenById(user.getBaolianrenId());
            user.setBaolianren(baolianren);
        }
        SysDept village = deptService.selectDeptById(user.getVillageId());
        String address = deptService.mergeAddress(village);
        user.setAddress(address);
        ClientUserOrder params = new ClientUserOrder();
        params.setClientUserId(id);
        List<ClientUserOrder> orders = clientUserOrderService.selectClientUserOrderList(params);
        modelMap.put("userInfo",user);
        modelMap.put("orders",orders);
    }
}
